using System;
using System.Linq;
using System.Runtime.Serialization;
using System.Data.Objects.DataClasses;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data.Objects;
using System.Text;
using Acme.Northwind.EFDAL;
using nHydrate.EFCore.DataAccess;
using nHydrate.EFCore.EventArgs;
using System.Text.RegularExpressions;
using System.Linq.Expressions;
using System.Data.Linq;

namespace Acme.Northwind.EFDAL.Entity
{
	/// <summary>
	/// The collection to hold 'CustomerandSuppliersbyCity' entities
	/// </summary>
	[EdmEntityTypeAttribute(NamespaceName="Acme.Northwind.EFDAL.Entity", Name="CustomerandSuppliersbyCity")]
	[Serializable()]
	[DataContractAttribute(IsReference = true)]
	[nHydrate.EFCore.Attributes.FieldNameConstantsAttribute(typeof(Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity.FieldNameConstants))]
	[System.ComponentModel.ImmutableObject(true)]
	[System.CodeDom.Compiler.GeneratedCode("nHydrateModelGenerator", "5.0.1.100")]
	public partial class CustomerandSuppliersbyCity : nHydrate.EFCore.DataAccess.NHEntityObject, nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject, Acme.Northwind.EFDAL.Interfaces.Entity.ICustomerandSuppliersbyCity, System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.ICustomerandSuppliersbyCity>
	{
		#region FieldNameConstants Enumeration

		/// <summary>
		/// Enumeration to define each property that maps to a database field for the 'CustomerandSuppliersbyCity' customView.
		/// </summary>
		public enum FieldNameConstants
		{
			/// <summary>
			/// Field mapping for the 'City' property
			/// </summary>
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'City' property")]
			City,
			/// <summary>
			/// Field mapping for the 'CompanyName' property
			/// </summary>
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'CompanyName' property")]
			CompanyName,
			/// <summary>
			/// Field mapping for the 'ContactName' property
			/// </summary>
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'ContactName' property")]
			ContactName,
			/// <summary>
			/// Field mapping for the 'Relationship' property
			/// </summary>
			[System.ComponentModel.ReadOnlyAttribute(true)]
			[System.ComponentModel.Description("Field mapping for the 'Relationship' property")]
			Relationship,
		}
		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity class
		/// </summary>
		protected internal CustomerandSuppliersbyCity()
		{
		}

		#endregion

		#region Properties

		[System.ComponentModel.Browsable(false)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = true, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("pk")]
		[System.ComponentModel.ReadOnly(true)]
		private Guid pk
		{
			get { return _pk; }
			set { _pk = value; }
		}
		private Guid _pk;

		/// <summary>
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("City")]
		[System.ComponentModel.ReadOnly(true)]
		public virtual string City
		{
			get { return _city; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.City))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "CustomerandSuppliersbyCity.City", GetMaxLength(FieldNameConstants.City)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "City");
				//this.OnCityChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("City");
				_city = eventArg.Value;
				ReportPropertyChanged("City");
				//this.OnCityChanged(eventArg);
			}
		}

		/// <summary>
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("CompanyName")]
		[System.ComponentModel.ReadOnly(true)]
		public virtual string CompanyName
		{
			get { return _companyName; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.CompanyName))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "CustomerandSuppliersbyCity.CompanyName", GetMaxLength(FieldNameConstants.CompanyName)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "CompanyName");
				//this.OnCompanyNameChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("CompanyName");
				_companyName = eventArg.Value;
				ReportPropertyChanged("CompanyName");
				//this.OnCompanyNameChanged(eventArg);
			}
		}

		/// <summary>
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = true)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("ContactName")]
		[System.ComponentModel.ReadOnly(true)]
		public virtual string ContactName
		{
			get { return _contactName; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.ContactName))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "CustomerandSuppliersbyCity.ContactName", GetMaxLength(FieldNameConstants.ContactName)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "ContactName");
				//this.OnContactNameChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("ContactName");
				_contactName = eventArg.Value;
				ReportPropertyChanged("ContactName");
				//this.OnContactNameChanged(eventArg);
			}
		}

		/// <summary>
		/// </summary>
		[System.ComponentModel.Browsable(true)]
		[EdmScalarPropertyAttribute(EntityKeyProperty = false, IsNullable = false)]
		[DataMemberAttribute()]
		[System.ComponentModel.DisplayName("Relationship")]
		[System.ComponentModel.ReadOnly(true)]
		public virtual string Relationship
		{
			get { return _relationship; }
			set
			{
				if ((value != null) && (value.Length > GetMaxLength(FieldNameConstants.Relationship))) throw new Exception(string.Format(GlobalValues.ERROR_DATA_TOO_BIG, value, "CustomerandSuppliersbyCity.Relationship", GetMaxLength(FieldNameConstants.Relationship)));
				var eventArg = new nHydrate.EFCore.EventArgs.ChangingEventArgs<string>(value, "Relationship");
				//this.OnRelationshipChanging(eventArg);
				if (eventArg.Cancel) return;
				ReportPropertyChanging("Relationship");
				_relationship = eventArg.Value;
				ReportPropertyChanged("Relationship");
				//this.OnRelationshipChanged(eventArg);
			}
		}

		#endregion

		#region Events

		/// <summary>
		/// The internal reference variable for the 'City' property
		/// </summary>
		protected string _city;

		/// <summary>
		/// The internal reference variable for the 'CompanyName' property
		/// </summary>
		protected string _companyName;

		/// <summary>
		/// The internal reference variable for the 'ContactName' property
		/// </summary>
		protected string _contactName;

		/// <summary>
		/// The internal reference variable for the 'Relationship' property
		/// </summary>
		protected string _relationship;

		#endregion

		#region GetMaxLength

		/// <summary>
		/// Gets the maximum size of the field value.
		/// </summary>
		public static int GetMaxLength(FieldNameConstants field)
		{
			switch (field)
			{
				case FieldNameConstants.City:
					return 30;
				case FieldNameConstants.CompanyName:
					return 80;
				case FieldNameConstants.ContactName:
					return 60;
				case FieldNameConstants.Relationship:
					return 9;
			}
			return 0;
		}

		int nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetMaxLength(Enum field)
		{
			return GetMaxLength((FieldNameConstants)field);
		}

		#endregion

		#region GetFieldType

		/// <summary>
		/// Gets the system type of a field on this object
		/// </summary>
		public static System.Type GetFieldType(FieldNameConstants field)
		{
			var o = new CustomerandSuppliersbyCity();
			return ((nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject)o).GetFieldType(field);
		}

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldType(Enum field)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");

			var array = Enum.GetValues(typeof(FieldNameConstants));
			switch ((FieldNameConstants)field)
			{
				case FieldNameConstants.City: return typeof(string);
				case FieldNameConstants.CompanyName: return typeof(string);
				case FieldNameConstants.ContactName: return typeof(string);
				case FieldNameConstants.Relationship: return typeof(string);
			}
			return null;
		}

		#endregion

		#region GetFieldNameConstants

		System.Type nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetFieldNameConstants()
		{
			return typeof(FieldNameConstants);
		}

		#endregion

		#region Get/Set Value

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field)
		{
			return ((nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject)this).GetValue(field, null);
		}

		object nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.GetValue(System.Enum field, object defaultValue)
		{
			if (field.GetType() != typeof(FieldNameConstants))
				throw new Exception("The '" + field.GetType().ReflectedType.ToString() + ".FieldNameConstants' value is not valid. The field parameter must be of type '" + this.GetType().ToString() + ".FieldNameConstants'.");
			return this.GetValue((FieldNameConstants)field, defaultValue);
		}

		#endregion

		#region PrimaryKey

		/// <summary>
		/// Hold the primary key for this object
		/// </summary>
		protected nHydrate.EFCore.DataAccess.IPrimaryKey _primaryKey = null;
		nHydrate.EFCore.DataAccess.IPrimaryKey nHydrate.EFCore.DataAccess.IReadOnlyBusinessObject.PrimaryKey
		{
			get { return null; }
		}

		#endregion

		#region IsParented

		/// <summary>
		/// Determines if this object is part of a collection or is detached
		/// </summary>
		[System.ComponentModel.Browsable(false)]
		public virtual bool IsParented
		{
		  get { return (this.EntityState != System.Data.EntityState.Detached); }
		}

		#endregion

		#region IsEquivalent

		/// <summary>
		/// Determines if all of the fields for the specified object exactly matches the current object.
		/// </summary>
		/// <param name="item">The object to compare</param>
		public override bool IsEquivalent(nHydrate.EFCore.DataAccess.INHEntityObject item)
		{
			if (item == null) return false;
			if (!(item is Acme.Northwind.EFDAL.Interfaces.Entity.ICustomerandSuppliersbyCity)) return false;
			var o = item as Acme.Northwind.EFDAL.Interfaces.Entity.ICustomerandSuppliersbyCity;
			return (
				o.City == this.City &&
				o.CompanyName == this.CompanyName &&
				o.ContactName == this.ContactName &&
				o.Relationship == this.Relationship
				);
		}

		#endregion

		#region Equals
		bool System.IEquatable<Acme.Northwind.EFDAL.Interfaces.Entity.ICustomerandSuppliersbyCity>.Equals(Acme.Northwind.EFDAL.Interfaces.Entity.ICustomerandSuppliersbyCity other)
		{
			return this.IsEquivalent(other);
		}
		#endregion

		#region GetValue

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field)
		{
			return GetValue(field, null);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public object GetValue(FieldNameConstants field, object defaultValue)
		{
			if (field == FieldNameConstants.City)
				return ((this.City == null) ? defaultValue : this.City);
			if (field == FieldNameConstants.CompanyName)
				return this.CompanyName;
			if (field == FieldNameConstants.ContactName)
				return ((this.ContactName == null) ? defaultValue : this.ContactName);
			if (field == FieldNameConstants.Relationship)
				return this.Relationship;
			throw new Exception("Field '" + field.ToString() + "' not found!");
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public int GetInteger(Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity.FieldNameConstants field)
		{
			return this.GetInteger(field, int.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public int GetInteger(Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity.FieldNameConstants field, int defaultValue)
		{
			var o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				int a;
				if (int.TryParse((string)o, out a))
					return a;
				else
					throw new System.InvalidCastException();
			}
			else
			{
				return (int)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public double GetDouble(Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity.FieldNameConstants field)
		{
			return this.GetDouble(field, double.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public double GetDouble(Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity.FieldNameConstants field, double defaultValue)
		{
			var o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				double a;
				if (double.TryParse((string)o, out a))
					return a;
				else
					throw new System.InvalidCastException();
			}
			else
			{
				return (double)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public System.DateTime GetDateTime(Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity.FieldNameConstants field)
		{
			return this.GetDateTime(field, System.DateTime.MinValue);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public System.DateTime GetDateTime(Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity.FieldNameConstants field, System.DateTime defaultValue)
		{
			var o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				System.DateTime a;
				if (System.DateTime.TryParse((string)o, out a))
					return a;
				else
					throw new System.InvalidCastException();
			}
			else
			{
				return (System.DateTime)o;
			}
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public string GetString(Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity.FieldNameConstants field)
		{
			return this.GetString(field, string.Empty);
		}

		/// <summary>
		/// Gets the value of one of this object's properties.
		/// </summary>
		public string GetString(Acme.Northwind.EFDAL.Entity.CustomerandSuppliersbyCity.FieldNameConstants field, string defaultValue)
		{
			var o = this.GetValue(field, defaultValue);
			if (o is string)
			{
				return (string)o;
			}
			else
			{
				return o.ToString();
			}
		}

		#endregion

		#region GetDatabaseFieldName

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(CustomerandSuppliersbyCity.FieldNameConstants field)
		{
			return GetDatabaseFieldName(field.ToString());
		}

		/// <summary>
		/// Returns the actual database name of the specified field.
		/// </summary>
		internal static string GetDatabaseFieldName(string field)
		{
			switch (field)
			{
				case "City": return "City";
				case "CompanyName": return "CompanyName";
				case "ContactName": return "ContactName";
				case "Relationship": return "Relationship";
			}
			return string.Empty;
		}

		#endregion

	}

}

